package com.sds.controller.main;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import com.sds.properties.Key;
import com.sds.reader.AbstractReader;
import com.sds.reader.PropertiesReader;
import com.sds.view.main.MainTextField;

public class MainFrameController implements ActionListener{
	private static final int DEFAULT_WIDTH = 800;
	private static final int DEFAULT_HEIGHT = 600;
	
	private static MainFrameController instance = null;
	
	private PropertiesReader pr = null; 
	
	private MainTextField mtf = null;
	
	public static MainFrameController getInstance() {
		if (instance == null) {
			instance = new MainFrameController();
		}
		return instance;
	}
	
	private MainFrameController() {
		pr = AbstractReader.getInstance(PropertiesReader.class, "config.properties");
		mtf = new MainTextField(this);
	}
	
	public int getWidth() {
		int ret = DEFAULT_WIDTH;
		
		String strWidth = pr.getProperty(Key.WINDOW_WIDTH);
				
		try {
			ret = Integer.valueOf(strWidth);
		} catch(Exception e) {
			
		}
		return ret;
	}
	
	public int getHeight() {
		int ret = DEFAULT_HEIGHT;
		String strHeight = pr.getProperty(Key.WINDOW_HEIGHT);
		
		
		try {
			ret = Integer.valueOf(strHeight);
		} catch(Exception e) {
			
		}
		return ret;
	}
	
	public String getTitle() {
		return pr.getProperty(Key.WINDOW_TITLE);
	}
	
	public MainTextField getMainTextField() {
		return mtf;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == mtf) {
			System.out.println(e.getActionCommand());
		}
	}
}
